Markdown is a way to make fancy documents. Make sure you “Knit” often – after every major change – to mitigate errors. Hashtags are how we make section levels of a doc.
This is bold. (that’s double asterisks). Or
italics. Or code.
To add a hyperlink, do [link text](url). without
backticks. For example, go here
To link to sections of your document, do
[link text](#section-name), without backticks, hyphens for
spaces, and only lowercase. For example, go
here.
To add more vertical space between blocks of text, use this: “ ” without quotes.
Should be more space now.
**To include an image inside the folder where your Rmd
file is located. Then type
![]full_image_filname_here){width = "50"}
RMarkdown is just Markdown with
R code woven in.
You can do R stuff in the same line as text. For example. 6 will show as 6. (It would look like bactick lower-case-r space then code then backtick).
You can also do a full-multi-line CHUNK of R stuff:
# ```{r}
3+3
## [1] 6
# ```
Settings to control how R chunks appear:
eval = TRUE: which actually runs the code; if
FALSE, it shows the code but doesn’t run it.echoe = TRUE: which shows the code; if
FALSE, the code can run without being seen.warnings = FALSE: which will turn off warnings.-fig.cap = "figure caption" adds a figure caption.
-fig.width = 7 example of figure width.
-fig.height = 4 example of figure height.
# this will be shown but not evaluated
3+3
## [1] 8
To manually set working directory while building up my Rmarkdown file, just go to Sessions > Set working directory > Source file location.
library(readr)
energy <- read_csv("../data/IRENA data.csv", skip = 1)
## Rows: 67200 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Country/area, Technology, Data Type, Grid connection, Electricity s...
## dbl (1): Year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
energy %>% names
## [1] "Country/area" "Technology" "Data Type"
## [4] "Grid connection" "Year" "Electricity statistics"
energy %>% head
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Afghanistan Total renewable Electricity Generation… On-grid 2000
## 2 Afghanistan Total renewable Electricity Generation… On-grid 2001
## 3 Afghanistan Total renewable Electricity Generation… On-grid 2002
## 4 Afghanistan Total renewable Electricity Generation… On-grid 2003
## 5 Afghanistan Total renewable Electricity Generation… On-grid 2004
## 6 Afghanistan Total renewable Electricity Generation… On-grid 2005
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% tail
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2019
## 2 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2020
## 3 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2021
## 4 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2022
## 5 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2023
## 6 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2024
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% pull(Technology) %>% unique %>% sort
## [1] "Biogas" "Coal and peat" "Geothermal energy"
## [4] "Natural gas" "Nuclear" "Offshore wind energy"
## [7] "Oil" "Onshore wind energy" "Renewable hydropower"
## [10] "Solar photovoltaic" "Total non-renewable" "Total renewable"
# filtered data
fenergy <-
energy %>%
filter(`Country/area` == 'United States of America (the)')
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <- ggplot(fenergy,
aes(x=Year,
y=as.numeric(`Electricity statistics`),
fill=Technology)) +
geom_area()
ggplotly(p)
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
## Warning: Removed 26 rows containing non-finite outside the scale range
## (`stat_align()`).